<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 配置上下文路径   -->
    <base th:href="@{/}">
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>书城首页</title>
    <link rel="stylesheet" href="css/minireset.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/iconfont.css"/>
    <link rel="stylesheet" href="css/index.css"/>
    <link rel="stylesheet" href="css/swiper.min.css"/>
</head>
<body>
<div id="app">
    <div class="topbar">
        <div class="w">
            <div class="topbar-left">
                <i>送至:</i>
                <i>北京</i>
                <i class="iconfont icon-ai-arrow-down"></i>
            </div>
            <!--  登录前风格  -->
            <div class="topbar-right" th:unless="${session.loginUser}">
                <a href="/login" class="login">登录</a>
                <a href="/register" class="register">注册</a>
            </div>
            <!--  登录后风格  -->
            <div class="topbar-right" th:if="${session.loginUser}">
                <span>欢迎你<b th:text="${session.loginUser.username}"></b></span>
                <a href="/logout" class="register">注销</a>
                <a href="cart?method=toCartPage" class="cart iconfont icon-gouwuche">
                    购物车
                    <div class="cart-num" th:if="${session.cart}" th:text="${session.cart.totalCount}"></div>
                </a>
                <a href="bookManager?method=toBookManagerPage" class="admin">后台管理</a>
            </div>
        </div>
    </div>
    <div class="header w">
        <a href="#" class="header-logo"></a>
        <div class="header-nav">
            <ul>
                <li><a href="#">java</a></li>
                <li><a href="#">前端</a></li>
                <li><a href="#">小说</a></li>
                <li><a href="#">文学</a></li>
                <li><a href="#">青春文学</a></li>
                <li><a href="#">艺术</a></li>
                <li><a href="#">管理</a></li>
            </ul>
        </div>
        <div class="header-search">
            <input type="text" placeholder="十万个为什么"/>
            <button class="iconfont icon-search"></button>
        </div>
    </div>
    <div class="banner w clearfix">
        <div class="banner-left">
            <ul>
                <li>
                    <a href="">
                        <span>文学 鉴赏</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>社科 研究</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>少儿 培训</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>艺术 赏析</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>生活 周边</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>文教 科技</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
                <li>
                    <a href="">
                        <span>热销 畅读</span>
                        <i class="iconfont icon-jiantou"></i
                        ></a>
                </li>
            </ul>
        </div>
        <div class="banner-right">
            <div class="swiper-container">
                <ul class="swiper-wrapper">
                    <li class="swiper-slide">
                        <img src="uploads/banner4.jpg" alt="">
                        <!-- <div class="banner-img"></div> -->
                    </li>
                    <li class="swiper-slide">
                        <img src="uploads/banner5.jpg" alt="">
                        <!-- <div class="banner-img"></div> -->
                    </li>
                    <li class="swiper-slide">
                        <img src="uploads/banner6.jpg" alt="">
                        <!-- <div class="banner-img"></div> -->
                    </li>
                </ul>
                <div class="swiper-button-prev"></div>

                <div class="swiper-button-next"></div>

                <!-- Add Pagination -->
                <div class="swiper-pagination"></div>
            </div>
        </div>
    </div>
    <div class="books-list ">
        <div class="w">
            <div class="list">
                <div class="list-header">
                    <div class="title">图书列表</div>
                    <div class="price-search">
                        <span>价格:</span>
                        <input type="text">
                        <span>-元</span>
                        <input type="text">
                        <span>元</span>
                        <button>查询</button>
                    </div>
                </div>
                <div class="list-content">
                    <div class="list-item" th:each="book : ${data.list}">
                        <img th:src="${book.imgPath}" alt="">
                        <p th:text="'书名: '+${book.bookName}"></p>
                        <p th:text="'作者: '+${book.author}"></p>
                        <p th:text="'价格: '+${book.price}"></p>
                        <p th:text="'销量: '+${book.sales}"></p>
                        <p th:text="'库存: '+${book.stock}"></p>
                        <button @click="addToCart($event)" th:book_id="${book.bookId}">加入购物车</button>

                    </div>
                </div>
                <!-- 分页数据 -->
                <div class="list-footer" th:include="segment/footer :: pagination('index')"></div>
            </div>
        </div>

    </div>
    <div class="cate w">
        <div class="list">
            <a href="" class="list-item">
                <i class="iconfont icon-java"></i>
                <span>java</span>
            </a>
            <a href="" class="list-item"
            ><i class="iconfont icon-h5"></i>h5</a
            >
            <a href="" class="list-item">
                <i class="iconfont icon-python"></i>python
            </a>
            <a href="" class="list-item"
            ><i class="iconfont icon-tianchongxing-"></i>pm</a
            >
            <a href="" class="list-item"
            ><i class="iconfont icon-php_elephant"></i>php</a
            >
            <a href="" class="list-item"
            ><i class="iconfont icon-go"></i>go</a
            >
        </div>
        <a href="" class="img">
            <img src="uploads/cate4.jpg" alt=""/>
        </a>
        <a href="" class="img">
            <img src="uploads/cate5.jpg" alt=""/>
        </a>
        <a href="" class="img">
            <img src="uploads/cate6.jpg" alt=""/>
        </a>
    </div>
    <div class="books">
        <div class="w">
            <div class="seckill">
                <div class="seckill-header">
                    <div class="title">
                        图书秒杀
                    </div>
                    <!-- <i class="iconfont icon-huanyipi"></i> -->
                </div>
                <div class="seckill-content">

                    <a href="" class="tip">
                        <h5>距离结束还有</h5>
                        <i class="iconfont icon-shandian"></i>
                        <div class="downcount">
                            <span class="time">00</span>
                            <span class="token">:</span>
                            <span class="time">00</span>
                            <span class="token">:</span>
                            <span class="time">00</span>
                        </div>
                    </a>


                    <a href="" class="books-sec">
                        <img src="uploads/congwanqingdaominguo.jpg" alt="">
                        <p>从晚晴到民国</p>
                        <div>
                            <span class="cur-price">￥28.9</span>
                            <span class="pre-price">￥36.5</span>
                        </div>
                        <button>立即购买</button>
                    </a>
                    <a href="" class="books-sec">
                        <img src="uploads/cyuyanrumenjingdian.jpg" alt="">
                        <p>c语言入门经典</p>
                        <div>
                            <span class="cur-price">￥55.9</span>
                            <span class="pre-price">￥68.5</span>
                        </div>
                        <button>立即购买</button>
                    </a>
                    <a href="" class="books-sec">
                        <img src="uploads/fusang.jpg" alt="">
                        <p>扶桑</p>
                        <div>
                            <span class="cur-price">￥30.9</span>
                            <span class="pre-price">￥47.5</span>
                        </div>
                        <button>立即购买</button>
                    </a>
                    <a href="" class="books-sec">
                        <img src="uploads/geihaizideshi.jpg" alt="">
                        <p>给孩子的诗</p>
                        <div>
                            <span class="cur-price">￥18.9</span>
                            <span class="pre-price">￥25.5</span>
                        </div>
                        <button>立即购买</button>
                    </a>


                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div th:include="segment/footer :: contact"></div>
        <div th:include="segment/footer :: copyright"></div>
    </div>


</div>
<script src="script/swiper.min.js"></script>
<script src="script/vue.js"></script>
<script src="script/axios.min.js"></script>
<script>

    const app = new Vue({
        el: "#app",
        data: {
            toPage: [[${data.currentPage}]]
        },
        methods: {
            goPage() {
                // 校验toPage的格式是否正确
                let reg = /^[1-9][0-9]*$/
                if (reg.test(this.toPage)) {
                    // 发送请求携带请求参数
                    location.href = "index?currentPage=" + this.toPage + "&pageSize=" + 10
                } else {
                    alert("请输入正确的页数")
                }
            },
            addToCart(event) {

                // 获取商品id
                let bookId = event.currentTarget.getAttribute("book_id")
                // 添加商品到购物车
                axios.get("cart", {
                    params: {
                        method: "addCartItem",
                        id: bookId
                    }
                }).then(response => {
                    alert("添加购物车成功")
                }).catch(error => {
                    alert("添加购物车失败")
                })
            }
        }
    })

    const swiper = new Swiper('.swiper-container', {
        autoplay: true,
        pagination: {
            el: '.swiper-pagination',
            dynamicBullets: true
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
        }
    })
</script>
</body>
</html>
